//
//  GoodsDetailViewController.m
//  JiuJiuShangCheng
//
//  Created by jiujiukeji on 2018/7/11.
//  Copyright © 2018年 jiujiukeji. All rights reserved.
//

#import "GoodsDetailViewController.h"
#import "SDCycleScrollView.h"
#import "GoodsDetailBottomV.h"
#import "GoodsDetailItemTableViewCell.h"
#import "CommentViewController.h"
#import "BuyViewController.h"
#import "GuiGeTopView.h"
#import "RecommendCollectionViewCell.h"
#import "GoodsModel.h"
#import "GoodsListViewController.h"
#import "GoodsTuWenViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDKUI/ShareSDKUI.h>
#import <ShareSDK/ShareSDK+Base.h>
#import "WenDaViewController.h"
#import "ShoppingCartViewController.h"
#import "LoginViewController.h"
#import "CartModel.h"
#import <GLKit/GLKit.h>
#import <CoreMotion/CoreMotion.h>
#import "PanoramaController.h"

@interface GoodsDetailViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView; // 轮播图
@property (nonatomic, strong) NSMutableArray *netImages; // 网络图片数组
@property (nonatomic, strong) UIView *blackBgV;
@property (nonatomic, strong) UIView *whiteV;
@property (nonatomic, strong) UITableView *guiGeTableView;
@property (nonatomic, strong) GuiGeTopView *guiGeTopV;
@property (nonatomic, strong) NSMutableArray *btnArray1;
@property (nonatomic, strong) NSMutableArray *btnArray2;
@property (nonatomic, strong) NSDictionary *goodsDic;
@property (nonatomic, assign) CGSize sizeLen1;
@property (nonatomic, assign) CGSize sizeLen2;
@property (nonatomic, strong) GoodsDetailBottomV *goodsDetailBottomV;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *recomendGoodsArray;
@property (nonatomic, strong) UILabel *kuCunLB;
@property (nonatomic, strong) NSArray *guiGeArray;
@property (nonatomic, strong) NSDictionary *guiGeDic;
@property (nonatomic, strong) NSMutableArray *titleArray2;
@property (nonatomic, assign) NSInteger index1;
@property (nonatomic, assign) NSInteger index2;
@property (nonatomic, strong) UIButton *jiaBtn;
@property (nonatomic, strong) UIButton *jianBtn;
@property (nonatomic, assign) NSInteger num;
@property (nonatomic, strong) UILabel *numLB;
@property (nonatomic, assign) NSInteger kuCunNum;
@property (nonatomic, strong) NSString *selectStr;
@property (nonatomic, assign) CGFloat h1;
@property (nonatomic, assign) CGFloat h2;


@end

@implementation GoodsDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColorWhite;
    
    self.index1 = 0;
    self.index2 = 0;
    self.num = 1;
    
    [self setUpUI];
    [self getGoodsDetail];
    [self isCollect];
    [self getSpecificationData];
    [self getCartData];
}
#pragma mark - 获取购物车数据
- (void)getCartData
{
    [MBProgressHUD showMessage:nil toView:self.view];
    [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/shop/shop.ashx?action=shopcart&companyid=%@&from=mobile",kServerURL,companyId] parameters:nil success:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        [MBProgressHUD hideHUDForView:self.view];
        
        if ([responseObject[@"status"] intValue] == 1) {
            
            self.goodsDetailBottomV.cartNumLB.text = [NSString stringWithFormat:@"%@",responseObject[@"sum"]];
        }
        
    } failure:^(NSError *error) {
        [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
        [self.tableView.mj_header endRefreshing];
    }];
}
#pragma mark - 获取商品详情
- (void)getGoodsDetail
{
    if (self.contentId) {
        [MBProgressHUD showMessage:nil toView:self.view];
        [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/content/content.ashx?action=content&companyid=%@&id=%@",kServerURL,companyId,self.contentId] parameters:nil success:^(id responseObject) {
            [MBProgressHUD hideHUDForView:self.view];
            
            if ([responseObject[@"status"] intValue] == 1) {
                self.goodsDic = responseObject[@"content"][0];
                self.sizeLen1 = [self.goodsDic[@"title"] boundingRectWithSize:CGSizeMake (rateWidth(660), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil].size;
                self.sizeLen2 = [self.goodsDic[@"text1"] boundingRectWithSize:CGSizeMake (rateWidth(660), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size;
                // 规格header赋值
                [self.guiGeTopV.goodsImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http:%@",self.goodsDic[@"images"]]]];
                self.guiGeTopV.goodsNameLB.text = self.goodsDic[@"title"];
                
                // 获取推荐商品
                [self recomendGoodsData];
            }
            
            [self.tableView reloadData];
            
        } failure:^(NSError *error) {
            [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
            
        }];
    }
}
#pragma mark - 推荐商品
- (void)recomendGoodsData
{
    if (self.goodsDic[@"classid"]) {
        NSString *url;
        url = [NSString stringWithFormat:@"%@/api/json/content/content.ashx?action=list&companyid=%@&channelid=105&classid=%@&pagesize=100000&pageindex=1&excludeid=%@",kServerURL,companyId,self.goodsDic[@"classid"],self.contentId];
        
        [MBProgressHUD showMessage:nil toView:self.view];
        [TFNetworking getWithURLString:url parameters:nil success:^(id responseObject) {
            
            [MBProgressHUD hideHUDForView:self.view];
            self.recomendGoodsArray = [NSMutableArray array];
            if ([responseObject[@"status"] intValue] == 1) {
                self.recomendGoodsArray = [GoodsModel mj_objectArrayWithKeyValuesArray:responseObject[@"list"]];
            }
            [self.tableView reloadData];
            [self.collectionView reloadData];
            
        } failure:^(NSError *error) {
            [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
        }];
    }
}
#pragma mark - 商品规格
- (void)getSpecificationData
{
    if (self.contentId) {
        [MBProgressHUD showMessage:nil toView:self.view];
        [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/shop/shop.ashx?action=shopdata&companyid=%@&id=%@",kServerURL,companyId,self.contentId] parameters:nil success:^(id responseObject) {
            [MBProgressHUD hideHUDForView:self.view];
            
            if ([responseObject[@"status"] intValue] == 1) {
                self.guiGeDic = [NSDictionary dictionaryWithDictionary:responseObject];
                self.guiGeArray = [NSArray array];
                self.guiGeArray = responseObject[@"shop_attribute"];
                // 更新价格库存
                [self updatePrice];
                
                NSDictionary *dic0 = self.guiGeArray[0];
                NSArray *array2 = dic0[@"shop_attribute_data"];
                if ([self.guiGeDic[@"shop_title2"] length] != 0) {
                    self.titleArray2 = [NSMutableArray array];
                    for (NSDictionary *dic in array2) {
                        [self.titleArray2 addObject:dic[@"shop_attribute_gg"]];
                    }
                }
                // 高度适配
                CGFloat length = 0;
                for (NSDictionary *dic in self.guiGeArray) {
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
                    length = length + [dic[@"shop_attribute_xh"] boundingRectWithSize:CGSizeMake(kScreenWidth, kScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width+35;
                }
                NSLog(@"--------%f",ceilf(length/(kScreenWidth-30)));
                self.h1 = ceilf(length/(kScreenWidth-30))*(rateHeight(54)+10)+10;
                
                CGFloat length1 = 0;
                for (NSDictionary *dic in array2) {
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
                    length1 = length1 + [dic[@"shop_attribute_gg"] boundingRectWithSize:CGSizeMake(kScreenWidth, kScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width+35;
                }
                NSLog(@"-------%f",ceilf(length1/(kScreenWidth-30)));
                self.h2 = ceilf(length1/(kScreenWidth-30))*(rateHeight(54)+10);
                
            }
            [self.guiGeTableView reloadData];
            
        } failure:^(NSError *error) {
            [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
        }];
    }
}
#pragma mark - 判断收藏
- (void)isCollect
{
    if (self.contentId) {
        [MBProgressHUD showMessage:nil toView:self.view];
        [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/content/content.ashx?action=checkcollection&companyid=%@&id=%@",kServerURL,companyId,self.contentId] parameters:nil success:^(id responseObject) {
            [MBProgressHUD hideHUDForView:self.view];
            
            if ([responseObject[@"status"] intValue] == 0) {
                // 已收藏
                [self.goodsDetailBottomV.collectBtn setImage:UIImageNamed(@"detailshoucang1") forState:(UIControlStateNormal)];
            } else if ([responseObject[@"status"] intValue] == 2) {
                // 未收藏
                [self.goodsDetailBottomV.collectBtn setImage:UIImageNamed(@"detailshoucang") forState:(UIControlStateNormal)];
            }
            
        } failure:^(NSError *error) {
            [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
            
        }];
    }
}
#pragma mark - 收藏/取消收藏
- (void)setCollect
{
    if ([[UserDefaults valueForKey:@"isLogin"] intValue] == 0) {
        // 未登录
        [TFHUD addRemindHUD:self.view message:@"请登录后重试"];
    } else {
        if (self.contentId) {
            [MBProgressHUD showMessage:nil toView:self.view];
            [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/content/content.ashx?action=collection&companyid=%@&id=%@",kServerURL,companyId,self.contentId] parameters:nil success:^(id responseObject) {
                [MBProgressHUD hideHUDForView:self.view];
                
                if ([responseObject[@"status"] intValue] == 1) {
                    // 收藏成功
                    [self.goodsDetailBottomV.collectBtn setImage:UIImageNamed(@"detailshoucang1") forState:(UIControlStateNormal)];
                } else if ([responseObject[@"status"] intValue] == 2) {
                    // 取消收藏成功收藏
                    [self.goodsDetailBottomV.collectBtn setImage:UIImageNamed(@"detailshoucang") forState:(UIControlStateNormal)];
                }
                
            } failure:^(NSError *error) {
                [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
                
            }];
        }
    }
}
#pragma mark - 加入购物车
- (void)addCartAction
{
    if ([[UserDefaults valueForKey:@"isLogin"] intValue] == 0) {
        // 未登录
        [self loginAction];
    } else {
        if (self.contentId) {
            NSDictionary *dic0 = self.guiGeArray[self.index1];
            NSArray *array2 = dic0[@"shop_attribute_data"];
            NSDictionary *dicSub = array2[self.index2];
            NSString *h = dicSub[@"shop_attribute_hh"];
            [MBProgressHUD showMessage:nil toView:self.view];
            [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/shop/shop.ashx?action=shoping&companyid=%@&id=%@&h=%@&s=%@&r=%@&from=mobile",kServerURL,companyId,self.contentId,h,[NSString stringWithFormat:@"%ld",self.num],@"3"] parameters:nil success:^(id responseObject) {
                [MBProgressHUD hideHUDForView:self.view];
                if ([responseObject[@"status"] intValue] == 10) {
                    [MBProgressHUD showSuccess:@"加入购物车成功"];
                    [self closeAction];
                    [self getCartData];
                } else {
                    [MBProgressHUD showError:responseObject[@"errMsg"]];
                }
                
            } failure:^(NSError *error) {
                [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
                
            }];
        }
    }
}
#pragma mark - 立即购买
- (void)buyAction
{
    if ([[UserDefaults valueForKey:@"isLogin"] intValue] == 0) {
        // 未登录
        [self loginAction];
    } else {
        if (self.contentId) {
            NSDictionary *dic0 = self.guiGeArray[self.index1];
            NSArray *array2 = dic0[@"shop_attribute_data"];
            NSDictionary *dicSub = array2[self.index2];
            NSString *h = dicSub[@"shop_attribute_hh"];
            [MBProgressHUD showMessage:nil toView:self.view];
            [TFNetworking getWithURLString:[NSString stringWithFormat:@"%@/api/json/shop/shop.ashx?action=shoping&companyid=%@&id=%@&h=%@&s=%@&r=%@&from=mobile",kServerURL,companyId,self.contentId,h,[NSString stringWithFormat:@"%ld",self.num],@"1"] parameters:nil success:^(id responseObject) {
                [MBProgressHUD hideHUDForView:self.view];
                if ([responseObject[@"status"] intValue] == 10) {
                    BuyViewController *buyVC = [[BuyViewController alloc] init];
                    buyVC.selectIdArray = @[responseObject[@"CartId"]];
                    [self.navigationController pushViewController:buyVC animated:YES];
                } else {
                    [MBProgressHUD showError:responseObject[@"errMsg"]];
                }
                
            } failure:^(NSError *error) {
                [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
                
            }];
        }
    }
}
- (void)setUpUI
{
    WeakSelf
    [self.view addSubview:self.tableView];
    
    // 返回按钮 分享按钮
    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [backBtn setImage:UIImageNamed(@"detailfanhui") forState:(UIControlStateNormal)];
    [backBtn sizeToFit];
    [self.view addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(rateWidth(25));
        make.top.equalTo(self.view).offset(rateHeight(75));
    }];
    [backBtn addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    
    UIButton *shareBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [shareBtn setImage:UIImageNamed(@"detailfenxaing") forState:(UIControlStateNormal)];
    [shareBtn sizeToFit];
    [self.view addSubview:shareBtn];
    [shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-rateWidth(25));
        make.top.equalTo(self.view).offset(rateHeight(75));
    }];
    [shareBtn addTarget:self action:@selector(shareActionP) forControlEvents:(UIControlEventTouchUpInside)];
    
    // bottomView
    GoodsDetailBottomV *bottomV = [[GoodsDetailBottomV alloc] initWithFrame:CGRectMake(0, kScreenHeight-rateHeight(100), kScreenWidth, rateHeight(100))];
    //    [bottomV.buyBtn addTarget:self action:@selector(buyAction) forControlEvents:(UIControlEventTouchUpInside)];
    // 立即购买
    [bottomV.buyBtn addActionHandler:^{
        // 选择规格
        if ([[UserDefaults valueForKey:@"isLogin"] intValue] == 0) {
            // 未登录
            [weakSelf loginAction];
        } else {
            [UIView animateWithDuration:0.4 animations:^{
                weakSelf.whiteV.frame = CGRectMake(0, kScreenHeight-rateHeight(900), kScreenWidth, rateHeight(900));
            }];
            weakSelf.blackBgV.hidden = NO;
        }
        
    }];
    self.goodsDetailBottomV = bottomV;
    [self.view addSubview:bottomV];
    // 收藏
    [bottomV.collectBtn addTarget:self action:@selector(setCollect) forControlEvents:(UIControlEventTouchUpInside)];
    // 加入购物车
    //    [bottomV.addShopCartBtn addTarget:self action:@selector(addCartAction) forControlEvents:(UIControlEventTouchUpInside)];
    [bottomV.addShopCartBtn addActionHandler:^{
        // 选择规格
        if ([[UserDefaults valueForKey:@"isLogin"] intValue] == 0) {
            // 未登录
            [weakSelf loginAction];
        } else {
            [UIView animateWithDuration:0.4 animations:^{
                weakSelf.whiteV.frame = CGRectMake(0, kScreenHeight-rateHeight(900), kScreenWidth, rateHeight(900));
            }];
            weakSelf.blackBgV.hidden = NO;
        }
        
    }];
    // 跳转购物车
    [bottomV.serviceBtn addActionHandler:^{
        ShoppingCartViewController *shoppingCartVC = [[ShoppingCartViewController alloc] init];
        shoppingCartVC.isTiaoZhuanType = 1;
        [self.navigationController pushViewController:shoppingCartVC animated:YES];
    }];
    
    self.blackBgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _blackBgV.backgroundColor = [UIColorBlack colorWithAlphaComponent:0.7];
    [self.view addSubview:_blackBgV];
    _blackBgV.hidden = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeAction)];
    [_blackBgV addGestureRecognizer:tap];
    
    self.whiteV = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight+30, kScreenWidth, rateHeight(900))];
    _whiteV.backgroundColor = UIColorWhite;
    [self.view addSubview:_whiteV];
    self.guiGeTopV = [[GuiGeTopView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, rateHeight(220))];
    [_whiteV addSubview:_guiGeTopV];
    // 加入购物车
    UIButton *btn1 = [UIButton buttonWithTitle:@"加入购物车" fontSize:16 titleColor:UIColorWhite background:UIColorFromRGB(0xfbc865) cornerRadius:0];
    [_whiteV addSubview:btn1];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(kScreenWidth/2, rateHeight(100)));
        make.left.bottom.equalTo(weakSelf.whiteV);
    }];
    // 加入购物车
    [btn1 addTarget:self action:@selector(addCartAction) forControlEvents:(UIControlEventTouchUpInside)];
    // 立即购买
    UIButton *btn2 = [UIButton buttonWithTitle:@"立即购买" fontSize:16 titleColor:UIColorWhite background:navBarColor cornerRadius:0];
    [_whiteV addSubview:btn2];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(kScreenWidth/2, rateHeight(100)));
        make.right.bottom.equalTo(weakSelf.whiteV);
    }];
    [btn2 addTarget:self action:@selector(buyAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    [_whiteV addSubview:self.guiGeTableView];
    // 库存
    UILabel *kuCunLB = [UILabel labelWithText:@"库存：0" textColor:UIColorFromRGB(0x333333) fontSize:13];
    [kuCunLB sizeToFit];
    [_whiteV addSubview:kuCunLB];
    [kuCunLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(btn1.mas_top).offset(-rateHeight(60));
        make.left.equalTo(weakSelf.whiteV).offset(rateWidth(20));
    }];
    self.kuCunLB = kuCunLB;
    
    // 数量编辑
    UIImageView *editImg = [[UIImageView alloc] init];
    editImg.image = UIImageNamed(@"numEditImg");
    [editImg sizeToFit];
    [_whiteV addSubview:editImg];
    [editImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.whiteV).offset(-rateWidth(40));
        make.centerY.equalTo(kuCunLB);
    }];
    editImg.userInteractionEnabled = YES;
    
    UILabel *numLB = [UILabel labelWithText:[NSString stringWithFormat:@"%ld",self.num] textColor:UIColorFromRGB(0x666666) fontSize:13];
    [numLB sizeToFit];
    [editImg addSubview:numLB];
    [numLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(editImg);
    }];
    self.numLB = numLB;
    
    self.jiaBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [_whiteV addSubview:_jiaBtn];
    [_jiaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30, 50));
        make.centerX.equalTo(editImg.mas_right);
        make.centerY.equalTo(editImg);
    }];
    self.jianBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [_whiteV addSubview:_jianBtn];
    [_jianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30, 50));
        make.centerX.equalTo(editImg.mas_left);
        make.centerY.equalTo(editImg);
    }];
    [_jiaBtn addTarget:self action:@selector(jiaAction) forControlEvents:(UIControlEventTouchUpInside)];
    [_jianBtn addTarget:self action:@selector(jianAction) forControlEvents:(UIControlEventTouchUpInside)];
}
- (void)loginAction
{
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    [self presentViewController:loginVC animated:YES completion:nil];
}
- (void)jiaAction
{
    if (self.num<self.kuCunNum) {
        self.num++;
        self.numLB.text = [NSString stringWithFormat:@"%ld",self.num];
    }
}
- (void)jianAction
{
    if (self.num>1) {
        self.num--;
        self.numLB.text = [NSString stringWithFormat:@"%ld",self.num];
    }
}
- (void)closeAction
{
    [UIView animateWithDuration:0.4 animations:^{
        self.whiteV.frame = CGRectMake(0, kScreenHeight+30, kScreenWidth, rateHeight(900));
    }];
    _blackBgV.hidden = YES;
}
#pragma mark - tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == _tableView) {
        return 5;
    } else {
        if ([self.guiGeDic[@"shop_title1"] length] != 0 && [self.guiGeDic[@"shop_title2"] length] != 0) {
            return 2;
        } else if ([self.guiGeDic[@"shop_title1"] length] != 0 && [self.guiGeDic[@"shop_title2"] length] == 0) {
            return 1;
        } else {
            return 0;
        }
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _tableView) {
        if (section == 0) {
            return 1;
        } else if (section == 1) {
            return 1;
        } else if (section == 2) {
            return 2;
        } else if (section == 3) {
            return 2;
        } else {
            return 1;
        }
    } else {
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _tableView) {
        if (indexPath.section == 2 || indexPath.section == 3) {
            GoodsDetailItemTableViewCell *cell = [[GoodsDetailItemTableViewCell alloc] init];
            if (indexPath.section == 2) {
                NSArray *array = @[@"选择规格",@"商品评价"];
                cell.leftLB.text = array[indexPath.row];
                if (indexPath.row == 0) {
                    cell.rightLB.hidden = NO;
                    cell.rightLB.text = self.selectStr;
                }
            } else {
                NSArray *array = @[@"图文详情",@"问答"];
                cell.leftLB.text = array[indexPath.row];
            }
            cell.selectionStyle = NO;
            return cell;
        } else {
            UITableViewCell *cell = [[UITableViewCell alloc] init];
            if (indexPath.section == 0) {
                // 轮播图
                if (self.goodsDic[@"imagesAll"]) {
                    self.netImages = [NSMutableArray array];
                    NSArray *array = [self.goodsDic[@"imagesAll"] componentsSeparatedByString:@","];
                    for (NSString *str in array) {
                        [self.netImages addObject:[NSString stringWithFormat:@"http:%@",str]];
                    }
                    self.cycleScrollView.autoScroll = YES;
                    [cell.contentView addSubview:self.cycleScrollView];
                    
                }
                
            } else if (indexPath.section == 1) {
                UILabel *label1 = [UILabel labelWithText:self.goodsDic[@"title"] textColor:UIColorFromRGB(0x323232) fontSize:15];
                [label1 sizeToFit];
                label1.numberOfLines = 0;
                [cell.contentView addSubview:label1];
                [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(cell.contentView).offset(rateWidth(30));
                    make.top.equalTo(cell.contentView).offset(rateWidth(30));
                    make.width.mas_lessThanOrEqualTo(@(rateWidth(660)));
                    //                    make.height.mas_lessThanOrEqualTo(@(rateHeight(80)));
                }];
                UILabel *label11 = [UILabel labelWithText:self.goodsDic[@"text1"] textColor:UIColorFromRGB(0x666666) fontSize:14];
                [label11 sizeToFit];
                label11.numberOfLines = 0;
                [cell.contentView addSubview:label11];
                [label11 mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(cell.contentView).offset(rateWidth(30));
                    make.top.equalTo(label1.mas_bottom).offset(rateWidth(20));
                    make.width.mas_lessThanOrEqualTo(@(rateWidth(660)));
                    //                    make.height.mas_lessThanOrEqualTo(@(rateHeight(70)));
                }];
                UILabel *label2 = [UILabel labelWithText:[NSString stringWithFormat:@"￥%.2f",[self.goodsDic[@"price"] floatValue]] textColor:UIColorFromRGB(0xf55555) fontSize:18];
                [label2 sizeToFit];
                [cell.contentView addSubview:label2];
                [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(label1);
                    make.top.equalTo(label11.mas_bottom).offset(rateWidth(20));
                }];
            } else if (indexPath.section == 4) {
                [cell.contentView addSubview:self.collectionView];
            }
            
            cell.selectionStyle = NO;
            return cell;
        }
    } else {
        WeakSelf
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        if (indexPath.section == 0) {
            NSMutableArray *listArray = [NSMutableArray array];
            for (NSDictionary *dic in self.guiGeArray) {
                [listArray addObject:dic[@"shop_attribute_xh"]];
            }
            if (listArray && listArray.count!=0) {
                CGFloat w = 0;//保存前一个button的宽以及前一个button距离屏幕边缘的距离
                CGFloat h = rateHeight(20);//用来控制button距离父视图的高
                self.btnArray1 = [NSMutableArray array];
                for (int i = 0; i < listArray.count; i++) {
                    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
                    button.layer.masksToBounds = YES;
                    button.layer.cornerRadius = 3;
                    button.tag = i;
                    button.backgroundColor = UIColorFromRGB(0xf0f2f5);
                    [button setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
                    if (i == self.index1) {
                        [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
                        button.backgroundColor = UIColorWithRGB(254, 69, 8);
                    }
                    [button whenTapped:^{
                        for (UIButton *btn in weakSelf.btnArray1) {
                            if (btn.tag == button.tag) {
                                self.index1 = button.tag;
                                [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
                                btn.backgroundColor = UIColorWithRGB(254, 69, 8);
                                
                                NSDictionary *dic0 = self.guiGeArray[self.index1];
                                NSArray *array2 = dic0[@"shop_attribute_data"];
                                
                                if ([self.guiGeDic[@"shop_title2"] length] != 0) {
                                    self.titleArray2 = [NSMutableArray array];
                                    for (NSDictionary *dic in array2) {
                                        [self.titleArray2 addObject:dic[@"shop_attribute_gg"]];
                                    }
                                    self.index2 = 0;
                                    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
                                    [self.guiGeTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
                                }
                                // 更新价格库存
                                [self updatePrice];
                                
                            } else {
                                [btn setTitleColor:UIColorFromRGB(0x666666) forState:(UIControlStateNormal)];
                                btn.backgroundColor = UIColorFromRGB(0xf0f2f5);
                            }
                        }
                        
                    }];
                    
                    //根据计算文字的大小
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};
                    CGFloat length = [listArray[i] boundingRectWithSize:CGSizeMake(kScreenWidth, kScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
                    //为button赋值
                    [button setTitle:listArray[i] forState:UIControlStateNormal];
                    //设置button的frame
                    button.frame = CGRectMake(15 + w, h, length + 35 , rateHeight(54));
                    //当button的位置超出屏幕边缘时换行 320 只是button所在父视图的宽度
                    if(15 + w + length + 15 > kScreenWidth-20){
                        w = 0; //换行时将w置为0
                        h = h + button.frame.size.height + 10;//距离父视图也变化
                        button.frame = CGRectMake(15 + w, h, length + 35, rateHeight(54));//重设button的frame
                    }
                    w = button.frame.size.width + button.frame.origin.x;
                    [cell.contentView addSubview:button];
                    [self.btnArray1 addObject:button];
                }
            }
        } else {
            //            if (self.index2 == 0) {
            [cell.contentView removeAllSubviews];
            NSArray *listArray = [NSArray arrayWithArray:self.titleArray2];
            if (listArray && listArray.count!=0) {
                CGFloat w = 0;//保存前一个button的宽以及前一个button距离屏幕边缘的距离
                CGFloat h = rateHeight(20);//用来控制button距离父视图的高
                self.btnArray2 = [NSMutableArray array];
                for (int i = 0; i < listArray.count; i++) {
                    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
                    button.layer.masksToBounds = YES;
                    button.layer.cornerRadius = 3;
                    button.tag = i;
                    button.backgroundColor = UIColorFromRGB(0xf0f2f5);
                    [button setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
                    if (i == self.index2) {
                        [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
                        button.backgroundColor = UIColorWithRGB(254, 69, 8);
                    }
                    [button whenTapped:^{
                        for (UIButton *btn in weakSelf.btnArray2) {
                            if (btn.tag == button.tag) {
                                [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
                                btn.backgroundColor = UIColorWithRGB(254, 69, 8);
                                self.index2 = button.tag;
                                // 更新价格库存
                                [self updatePrice];
                            } else {
                                [btn setTitleColor:UIColorFromRGB(0x666666) forState:(UIControlStateNormal)];
                                btn.backgroundColor = UIColorFromRGB(0xf0f2f5);
                            }
                        }
                        
                    }];
                    
                    //根据计算文字的大小
                    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};
                    CGFloat length = [listArray[i] boundingRectWithSize:CGSizeMake(kScreenWidth, kScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
                    //为button赋值
                    [button setTitle:listArray[i] forState:UIControlStateNormal];
                    //设置button的frame
                    button.frame = CGRectMake(15 + w, h, length + 35 , rateHeight(54));
                    //当button的位置超出屏幕边缘时换行 320 只是button所在父视图的宽度
                    if(15 + w + length + 15 > kScreenWidth-20){
                        w = 0; //换行时将w置为0
                        h = h + button.frame.size.height + 10;//距离父视图也变化
                        button.frame = CGRectMake(15 + w, h, length + 35, rateHeight(54));//重设button的frame
                    }
                    w = button.frame.size.width + button.frame.origin.x;
                    [cell.contentView addSubview:button];
                    [self.btnArray2 addObject:button];
                }
            }
            //            }
        }
        cell.selectionStyle = NO;
        return cell;
    }
    
}
#pragma mark - 分享按钮
- (void)shareActionP
{
    //1、创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:self.goodsDic[@"text1"]
                                     images:@[[NSString stringWithFormat:@"http:%@",self.goodsDic[@"images"]]]
                                        url:[NSURL URLWithString:[NSString stringWithFormat:@"%@/content/%@.aspx",shareUrl,self.goodsDic[@"id"]]]
                                      title:self.goodsDic[@"title"]
                                       type:SSDKContentTypeAuto];
    //有的平台要客户端分享需要加此方法，例如微博
    [shareParams SSDKEnableUseClientShare];
    //    [shareParams SSDKEnableExtensionShare];
    //2、分享（可以弹出我们的分享菜单和编辑界面）
    [ShareSDK showShareActionSheet:nil // 要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图，只有传这个才可以弹出我们的分享菜单，可以传分享的按钮对象或者自己创建小的view 对象，iPhone可以传nil不会影响
                             items:nil
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                   switch (state) {
                       case SSDKResponseStateSuccess:
                       {
                           UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                               message:nil
                                                                              delegate:nil
                                                                     cancelButtonTitle:@"确定"
                                                                     otherButtonTitles:nil];
                           [alertView show];
                           break;
                       }
                       case SSDKResponseStateFail:
                       {
                           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                           message:[NSString stringWithFormat:@"%@",error]
                                                                          delegate:nil
                                                                 cancelButtonTitle:@"OK"
                                                                 otherButtonTitles:nil, nil];
                           [alert show];
                           break;
                       }
                       default:
                           break;
                   }
               }
     ];
}
#pragma mark - 更新价格库存
- (void)updatePrice
{
    NSDictionary *dic0 = self.guiGeArray[self.index1];
    NSArray *array2 = dic0[@"shop_attribute_data"];
    NSDictionary *dicSub = array2[self.index2];
    self.guiGeTopV.originalPriceLB.text = [NSString stringWithFormat:@"￥%.2f",[dicSub[@"shop_attribute_price2"] floatValue]];
    self.guiGeTopV.currentPriceLB.text = [NSString stringWithFormat:@"￥%.2f",[dicSub[@"shop_attribute_price"] floatValue]];
    self.kuCunLB.text = [NSString stringWithFormat:@"库存：%@",dicSub[@"shop_attribute_stock"]];
    self.kuCunNum = [dicSub[@"shop_attribute_stock"] intValue];
    //    [self.guiGeTopV.goodsImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http:%@",dic0[@"shop_attribute_smallpic"]]]];
    self.selectStr = [NSString stringWithFormat:@"已选：%@ %@",dic0[@"shop_attribute_xh"],dicSub[@"shop_attribute_gg"]];
    //一个cell刷新
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:2];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    
    CGFloat length1 = 0;
    for (NSDictionary *dic in array2) {
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
        length1 = length1 + [dic[@"shop_attribute_gg"] boundingRectWithSize:CGSizeMake(kScreenWidth, kScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width+35;
    }
    NSLog(@"------%f",ceilf(length1/(kScreenWidth-30)));
    self.h2 = ceilf(length1/(kScreenWidth-30))*(rateHeight(54)+10);
    [self.guiGeTableView reloadData];
}
- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _tableView) {
        if (indexPath.section == 0) {
            return kScreenWidth;
        } else if (indexPath.section == 1) {
            return rateWidth(140)+_sizeLen1.height+_sizeLen2.height;
        } else if (indexPath.section == 4) {
            // 推荐
            if (self.recomendGoodsArray.count == 0) {
                return 0.01;
            } else if (self.recomendGoodsArray > 0 && self.recomendGoodsArray.count < 4) {
                return rateWidth(350);
            } else {
                return rateWidth(350)*2;
            }
            
        } else {
            return rateWidth(90);
        }
    } else {
        if (indexPath.section == 0) {
            return self.h1;
        } else {
            return self.h2;
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (tableView == _tableView) {
        if (section == 4) {
            return rateWidth(100);
        } else {
            return 0.01;
        }
        
    } else {
        return rateWidth(60);
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (tableView == _tableView) {
        if (section == 0) {
            return 0.01;
        } else {
            return rateWidth(10);
        }
        
    } else {
        return 0.01;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (tableView == _guiGeTableView) {
        UIView *bgV = [[UIView alloc] init];
        bgV.backgroundColor = UIColorWhite;
        NSArray *array = [NSArray array];
        if ([self.guiGeDic[@"shop_title1"] length] != 0 && [self.guiGeDic[@"shop_title2"] length] != 0) {
            array = @[self.guiGeDic[@"shop_title1"],self.guiGeDic[@"shop_title2"]];
        } else if ([self.guiGeDic[@"shop_title1"] length] != 0 && [self.guiGeDic[@"shop_title2"] length] == 0) {
            array = @[self.guiGeDic[@"shop_title1"]];
        } else {
            array = nil;
        }
        UILabel *label = [UILabel labelWithText:array[section] textColor:UIColorFromRGB(0x333333) fontSize:16];
        [label sizeToFit];
        [bgV addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(bgV);
            make.left.equalTo(bgV).offset(rateWidth(20));
        }];
        
        return bgV;
    } else {
        if (section == 4) {
            UIView *bgV = [[UIView alloc] init];
            bgV.backgroundColor = UIColorWhite;
            
            UILabel *label = [UILabel labelWithText:@"为你推荐" textColor:UIColorFromRGB(0x333333) fontSize:15];
            [label sizeToFit];
            [bgV addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(bgV);
            }];
            
            UIImageView *arrow = [[UIImageView alloc] init];
            arrow.image = UIImageNamed(@"rightArrow");
            [arrow sizeToFit];
            [bgV addSubview:arrow];
            [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(bgV);
                make.right.equalTo(bgV).offset(-rateWidth(30));
            }];
            arrow.userInteractionEnabled = YES;
            
            UILabel *label1 = [UILabel labelWithText:@"更多" textColor:UIColorFromRGB(0x666666) fontSize:15];
            [label1 sizeToFit];
            [bgV addSubview:label1];
            [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(bgV);
                make.right.equalTo(arrow.mas_left).offset(-rateWidth(20));
            }];
            UIView *line = [[UIView alloc] init];
            line.backgroundColor = tableViewBgColor;
            [bgV addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.equalTo(bgV);
                make.height.equalTo(@(rateWidth(2)));
            }];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore)];
            [bgV addGestureRecognizer:tap];
            
            return bgV;
        } else {
            return nil;
        }
    }
}
- (void)actionMore
{
    if (self.goodsDic[@"classid"]) {
        GoodsListViewController *goodsListVC = [[GoodsListViewController alloc] init];
        goodsListVC.classid = self.goodsDic[@"classid"];
        [self.navigationController pushViewController:goodsListVC animated:YES];
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _tableView) {
        if (indexPath.section == 2 && indexPath.row == 1) {
            // 评论
            CommentViewController *commentVC = [[CommentViewController alloc] init];
            commentVC.goodsId = self.contentId;
            [self.navigationController pushViewController:commentVC animated:YES];
        } else if (indexPath.section == 2 && indexPath.row == 0) {
            // 选择规格
            [UIView animateWithDuration:0.4 animations:^{
                self.whiteV.frame = CGRectMake(0, kScreenHeight-rateHeight(900), kScreenWidth, rateHeight(900));
            }];
            _blackBgV.hidden = NO;
        } else if (indexPath.section == 3 && indexPath.row == 0) {
            // 图文详情
            GoodsTuWenViewController *tuWenVC = [[GoodsTuWenViewController alloc] init];
            tuWenVC.tuWenStr = self.goodsDic[@"content"];
            [self.navigationController pushViewController:tuWenVC animated:YES];
        } else if (indexPath.section == 3 && indexPath.row == 1) {
            // 问答
            WenDaViewController *wenDaVC = [[WenDaViewController alloc] init];
            wenDaVC.goodsId = self.contentId;
            [self.navigationController pushViewController:wenDaVC animated:YES];
        }
    }
}
#pragma mark - collectionview delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (_recomendGoodsArray.count > 6) {
        return 6;
    } else {
        return _recomendGoodsArray.count;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell" forIndexPath:indexPath];
    cell.contentView.backgroundColor = UIColorWhite;
    if (_recomendGoodsArray.count != 0) {
        GoodsModel *model = _recomendGoodsArray[indexPath.row];
        [cell.goodsImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http:%@",model.images]]];
        cell.titleLB.text = model.title;
        cell.priceLB.text = [NSString stringWithFormat:@"￥%.2f",[model.price floatValue]];
    }
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(kScreenWidth/3, rateWidth(350));
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (_recomendGoodsArray.count != 0) {
        GoodsModel *model =_recomendGoodsArray[indexPath.row];
        GoodsDetailViewController *goodsD = [[GoodsDetailViewController alloc] init];
        goodsD.contentId = model.id;
        [self.navigationController pushViewController:goodsD animated:YES];
    }
}
#pragma mark - 轮播图
- (SDCycleScrollView *)cycleScrollView
{
    WeakSelf
    if (!_cycleScrollView) {
        // 轮播图
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenWidth) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        _cycleScrollView.delegate = self;
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.pageDotColor = UIColorWhite;
        _cycleScrollView.currentPageDotColor = UIColorFromRGB(0xf55555);
        
        //        _cycleScrollView.pageDotImage = UIImageNamed(@"segmentGray");
        _cycleScrollView.pageControlDotSize = CGSizeMake(rateWidth(15), rateWidth(20));
        //        _cycleScrollView.currentPageDotImage = UIImageNamed(@"segmentRed");
        
        // 模拟延迟加载
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            weakSelf.cycleScrollView.imageURLStringsGroup = weakSelf.netImages;
        });
        // 清除缓存
        [self.cycleScrollView clearCache];
    }
    return _cycleScrollView;
}
#pragma mark - 轮播图点击
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", index);
    
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -TopHeight, kScreenWidth, kScreenHeight+TopHeight-rateHeight(100)) style:(UITableViewStyleGrouped)];
        _tableView.backgroundColor = tableViewBgColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = NO;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
    }
    return _tableView;
}
- (UITableView *)guiGeTableView
{
    if (!_guiGeTableView) {
        _guiGeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, rateHeight(220), kScreenWidth, rateHeight(900)-rateHeight(220)-rateHeight(100)-rateHeight(150)) style:(UITableViewStyleGrouped)];
        _guiGeTableView.backgroundColor = UIColorWhite;
        _guiGeTableView.delegate = self;
        _guiGeTableView.dataSource = self;
        _guiGeTableView.separatorStyle = NO;
        _guiGeTableView.estimatedRowHeight = 0;
        _guiGeTableView.estimatedSectionFooterHeight = 0;
        _guiGeTableView.estimatedSectionHeaderHeight = 0;
    }
    return _guiGeTableView;
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, rateWidth(700)) collectionViewLayout:layout];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.backgroundColor = kClearColor;
        [_collectionView registerClass:[RecommendCollectionViewCell class] forCellWithReuseIdentifier:@"collectionViewCell"];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.scrollEnabled = NO;
        
    }
    return _collectionView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
